﻿<Page
    x:Class="SgfEdwin8.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SgfEdwin8"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
        Background="#C7419082"
        KeyDown="mainWin_keydown" 
        SizeChanged="Page_SizeChanged"
    >

    <!-- Need this apparently to avoid error about setting content twice with two top level grids.
         May need to wrap this grid in this following scrollviewer to have a fallback for handling any resolution,
         due to smaller displays, fill view, etc:
        <ScrollViewer ZoomMode="Disabled" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Visible">
        </ScrollViewer>
    -->
    <Grid x:Name="switchableContentRoot">

        <!-- Define the main UI Grid: buttons upper right, edit box below, go board down the left side ... -->
        <Grid x:Name="mainLandscapeView" Background="#C7419082">
        <!-- Background="{StaticResource ApplicationPageBackgroundThemeBrush}" -->
        <Grid.RowDefinitions>
            <RowDefinition Height="150" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <!--<ColumnDefinition Width="320*" />-->
            <!--<ColumnDefinition Width="183*" />-->
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="600" /> <!-- This width must match hardcoded value in Page_SizeChanged -->
        </Grid.ColumnDefinitions>

        <!-- Define the comment box and tree control with splitter and scroll bars ... -->
        <Grid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Stretch" >
            <Grid.RowDefinitions>
                <RowDefinition Height="48"/>
                <RowDefinition  />
                <RowDefinition Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <!-- margin is "left, top, right, bottom"-->
            <StackPanel Grid.Row="0" Background="DarkKhaki" Margin="2,0,0,0">
                <TextBlock Text="SGF Editor -- " FontSize="16" Margin="4,2,1,1"
                           VerticalAlignment="Center" HorizontalAlignment="Stretch" x:Name="Title"/>
                <TextBlock Text="Move 0" FontSize="16" Margin="4,1,1,3"
                           VerticalAlignment="Center" HorizontalAlignment="Stretch" x:Name="TitleLine2"/>
            </StackPanel>
            <TextBox Grid.Row="1" HorizontalAlignment="Stretch" Margin="2,2,2,1" Name="commentBox" 
                     VerticalAlignment="Stretch" TextWrapping="Wrap" AcceptsReturn="True"
                     ScrollViewer.HorizontalScrollBarVisibility="Auto" 
                     ScrollViewer.VerticalScrollBarVisibility="Auto" />
            <ScrollViewer Grid.Row="3" Margin="2,1,2,2" ScrollViewer.HorizontalScrollBarVisibility="Visible" 
                          ScrollViewer.VerticalScrollBarVisibility="Visible" >
                <Canvas Name="gameTreeView" Background="Wheat" ScrollViewer.HorizontalScrollBarVisibility="Visible" 
                        ScrollViewer.VerticalScrollBarVisibility="Visible" PointerPressed="gameTree_mousedown" >
                </Canvas>
            </ScrollViewer>
        </Grid> <!-- comment box, tree view, ...-->



        <!-- Define the Grid for the control buttons in the upper right ... -->
            <Grid Grid.Column="1" HorizontalAlignment="Stretch" Margin="2,2,2,2" Name="buttonsGrid" 
                  VerticalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <!-- Need to learn how to make a File menu ... -->
                <!--
            <Button Grid.Row="0" Height="30" HorizontalAlignment="Stretch" Margin="1" Name="newButton"
                    VerticalAlignment="Top" Width="70" Click="newButton_left_down" 
                    BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" Foreground="Black">
                <TextBlock FontSize="14" FontStretch="ExtraExpanded" VerticalAlignment="Center"
                           HorizontalAlignment="Center">New</TextBlock>
            </Button>
            <Button Grid.Row="0" Grid.Column="1" Height="30" HorizontalAlignment="Stretch" Margin="1" 
                    Name="openButton" VerticalAlignment="Top" Width="70" Click="openButton_left_down"
                    BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" Foreground="Black">
                <TextBlock FontSize="14" FontStretch="ExtraExpanded" VerticalAlignment="Center" 
                           Margin="0,0,0,3">Open</TextBlock>
            </Button>
            -->

                <!-- Grid for Save, Help, Branches, and move/triangle/square/letter palette -->
                <Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4" 
                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*" />
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Button Grid.Row="0" Grid.Column="2" Height="40" HorizontalAlignment="Stretch" Margin="1" 
                            Name="saveButton" VerticalAlignment="Center" Width="70" Click="saveButton_left_down"
                            BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" Foreground="Black">
                        <TextBlock FontSize="16" VerticalAlignment="Center" Margin="0,0,0,3">Save</TextBlock>
                    </Button>
                    <Button Grid.Row="0" Grid.Column="3" Height="40" HorizontalAlignment="Stretch" Margin="1" 
                            Name="helpButton" VerticalAlignment="Center" Width="70" Click="helpButtonLeftDown"
                            BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" Foreground="Black">
                        <TextBlock FontSize="16" VerticalAlignment="Center" Margin="0,0,0,3">Help</TextBlock>
                    </Button>

                    <!--
                    <StackPanel Grid.Column="1" Grid.Row="1" Background="Transparent" Margin="0,2,0,2" Height="70"
                            HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <TextBlock FontSize="14" Margin="2,5,2,2" Width="120"
                            >Clicking on board:</TextBlock>
                        <ComboBox BorderThickness="1" Background="AntiqueWhite" Width="120" Height="25" SelectedIndex="0"
                            Name="boardClickCombo"  IsEnabled="True" SelectionChanged="boardClickComboSelectionChanged">
                            <ComboBoxItem>Move</ComboBoxItem>
                            <ComboBoxItem>Letter</ComboBoxItem>
                            <ComboBoxItem>Triangle</ComboBoxItem>
                            <ComboBoxItem>Square</ComboBoxItem>
                        </ComboBox>
                    </StackPanel>
                    -->

                    <StackPanel Grid.Column="1" Grid.Row="0" Background="Transparent" Margin="0,5,20,2" Height="70"
                                HorizontalAlignment="Center">
                        <TextBlock FontSize="14" Name="branchLabel" Margin="2,5,2,2" Width="120"
                               >No Branches:</TextBlock>
                        <ComboBox BorderThickness="1" Background="White" Width="120" Height="30" 
                              Name="branchCombo"  IsEnabled="False" SelectionChanged="branchComboSelectionChanged">
                        </ComboBox>
                    </StackPanel>

                    <Grid Grid.Row="0" Grid.Column="0"  Height="40" Margin="20,0,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*" />
                            <ColumnDefinition Width="2*" />
                            <ColumnDefinition Width="2*" />
                            <ColumnDefinition Width="3*" />
                        </Grid.ColumnDefinitions>
                        <Button IsEnabled="False" BorderThickness="1" Click="MoveButtonClick" Grid.Column="0"
                                HorizontalAlignment="Center"
                            x:Name="MoveButton"
                            >
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Ellipse Grid.Column="0" Grid.Row="0" Fill="Black" Width="10" Height="10" ></Ellipse>
                                <Ellipse Grid.Column="1" Grid.Row="1" Fill="White" Width="10" Height="10"></Ellipse>
                            </Grid>
                        </Button>
                        <Button IsEnabled="True" BorderThickness="0" Click="TriangleButtonClick" Grid.Column="1"
                                HorizontalAlignment="Center" x:Name="TriangleButton">
                            <Polygon Points="10,0,0,20,20,20" Stroke="White" StrokeThickness="1" />
                        </Button>
                        <Button IsEnabled="True" BorderThickness="0" Click="SquareButtonClick" Grid.Column="2"
                                HorizontalAlignment="Center" x:Name="SquareButton">
                            <Rectangle Height="20" Width="20" StrokeThickness="1" Stroke="White"/>
                        </Button>
                        <Button IsEnabled="True" BorderThickness="0" Click="LetterButtonClick" Grid.Column="3"
                                HorizontalAlignment="Left" x:Name="LetterButton" Foreground="White"
                                >A,B,C</Button>
                    </Grid>

                </Grid>
            <!--
            <Button Grid.Row="1" Height="30" HorizontalAlignment="Stretch" Margin="1" Name="passButton"
                    VerticalAlignment="Center" Width="70" Click="passButton_left_down"
                    BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" Foreground="Black">
                <TextBlock FontSize="14" VerticalAlignment="Center" Margin="0,0,0,3">Pass</TextBlock>
            </Button>
            -->
            
            <Button Content="&lt;&lt;" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" 
                    Margin="1,1,1,1" Name="homeButton" VerticalAlignment="Stretch" IsEnabled="False" 
                    Click="homeButtonLeftDown" 
                    FontSize="30" BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" 
                    Foreground="Black"/>
            <Button Content="&lt;" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" 
                    Margin="1,1,1,1" 
                    Name="prevButton" VerticalAlignment="Stretch" IsEnabled="False" Click="prevButtonLeftDown" 
                    FontSize="30" BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" 
                    Foreground="Black"/>
            <Button Content="&gt;" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Stretch" 
                    Margin="1,1,1,1" 
                    Name="nextButton" VerticalAlignment="Stretch"  IsEnabled="False" Click="nextButtonLeftDown"
                    FontSize="30" BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" 
                    Foreground="Black"/>
            <Button Content="&gt;&gt;" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Stretch" 
                    Margin="1,1,1,1" Name="endButton" VerticalAlignment="Stretch" IsEnabled="False" 
                    Click="endButtonLeftDown"
                    FontSize="30" BorderThickness="1" BorderBrush="Black" Background="LightGray" Padding="0" 
                    Foreground="Black"/>

        </Grid>  <!-- upper right control buttons -->

        <!-- Needed to contain the Go board lines and stones grids because grids can't have focus in winrt -->
        <local:FocusableInputControl x:Name="inputFocus" Grid.RowSpan="2" Margin="2,2,2,2" HorizontalAlignment="Stretch" 
                                     VerticalAlignment="Stretch">
            <Grid>
                <!-- Define the grid to hold board lines, which is filled in programmatically depending on the 
                     go board size ... -->
                <Grid Background="#FFD7B264" HorizontalAlignment="Stretch" x:Name="boardGrid"
                      VerticalAlignment="Stretch"  >
                </Grid>

                <!-- Define the grid to hold go stones, whose rows and columns are filled in programmatically -->
                <!-- ShowGridLines="False" -->
                <Grid  Background="Transparent" HorizontalAlignment="Stretch" IsHitTestVisible="True"
                       x:Name="stonesGrid" VerticalAlignment="Stretch" PointerPressed="StonesPointerPressed" >
                </Grid>
            </Grid>
        </local:FocusableInputControl>

    </Grid> <!-- main grid for buttons, board, comments -->
        
    
    <!-- Define the snapped view content (required in win8/8.1), 
         which starts off collapsed and possibly gets toggled on size change in win8.1, never hit on win10 -->
    <Grid x:Name="snapViewContent" Background="#C7419082" Visibility="Collapsed" HorizontalAlignment="Stretch" 
            VerticalAlignment="Stretch">
        <!-- Define the grid to hold board lines, which is filled in programmatically depending on the go board 
                size ... -->
        <Grid Background="#FFD7B264" HorizontalAlignment="Stretch" x:Name="collapsedBoardGrid" Grid.Row="0" 
                Grid.Column="0" VerticalAlignment="Stretch"  >
        </Grid>

        <!-- Define the grid to hold go stones, whose rows and columns are filled in programmatically ... -->
        <Grid Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" 
                Grid.Column="0" x:Name="collapsedStonesGrid"  >
        </Grid>
        </Grid>
        
    </Grid> <!-- switchableContentRoot -->
    

    <!-- App Bar for touch screens and moving less frequent commands out of command panel -->
    <Page.BottomAppBar>
        <AppBar x:Name="theAppBar">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <!-- Change what clicking on the board means ... -->
                <!--
                <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="18" x:Name="appBarClickText"
                           Margin="5,20">Clicking on board creates ... Moves</TextBlock>
                <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" Margin="20,0,10,10" >
                    <Button IsEnabled="False" BorderThickness="1" Click="AppBarMoveButtonClick"
                            x:Name="appBarMoveButton"
                            >Move</Button>
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarTriangleButtonClick"
                            x:Name="appBarTriangleButton">Triangle</Button>
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarLetterButtonClick"
                            x:Name="appBarLetterButton">Letter</Button>
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarSquareButtonClick"
                            x:Name="appBarSquareButton">Square</Button>
                </StackPanel>
                -->
                <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarGameInfoClick"
                            >Game Info ...</Button>
                    <Button IsEnabled="True" BorderThickness="1" Margin="73,0,0,0"  Click="AppBarGotoGame"
                            >Goto Game ...</Button>
                </StackPanel>
                <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal"  >
                    <Button Margin="0,0,10,0" Name="newButton" Click="newButton_left_down" 
                            BorderThickness="1" >New</Button>
                    <Button Margin="0,0,50,0" Name="openButton" Click="openButton_left_down" 
                            BorderThickness="1" >Open</Button>
                    <Button Name="passButton" Click="passButton_left_down"
                            BorderThickness="1" >Pass</Button>
                </StackPanel>

                <!-- Save As and Save Flipped ... -->
                <TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" FontSize="18"
                           Margin="20,20">Saving files:</TextBlock>
                <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" Margin="35,0,0,10" >
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarSaveAsClick"
                            x:Name="appBarSaveAsButton"
                            >Save As ...</Button>
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarSaveFlippedClick"
                            x:Name="appBarSaveFlippedButton">Save Flipped ...</Button>
                </StackPanel>
                <!-- Move Branches up or down ... -->
                <TextBlock Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" FontSize="18"
                           Margin="5,20">Move branch higher or lower:</TextBlock>
                <StackPanel Grid.Row="1" Grid.Column="2" Orientation="Horizontal" Margin="20,0,0,10" >
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarMoveUpClick"
                            x:Name="appBarMoveUpButton"
                            >Move Up</Button>
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarMoveDownClick"
                            x:Name="appBarMoveDownButton">Move Down</Button>
                </StackPanel>
                <!-- Cut or Paste a sub tree of moves ... -->
                <TextBlock Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" FontSize="18"
                           Margin="5,20">Cut or Paste a sub tree of moves:</TextBlock>
                <StackPanel Grid.Row="1" Grid.Column="3" Orientation="Horizontal" Margin="20,0,0,10" >
                    <Button IsEnabled="True" BorderThickness="1" Click="AppBarCutClick"
                            x:Name="appBarCutButton"
                            >Cut</Button>
                    <Button IsEnabled="False" BorderThickness="1" Click="AppBarPasteClick"
                            x:Name="appBarPasteButton">Paste</Button>
                </StackPanel>
            </Grid>
        </AppBar>

    </Page.BottomAppBar>
</Page>
